package com.example.front.arrange;

import lombok.Data;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;

@Data
@Slf4j
class Config {

    private Integer id;

    private String taskName;

    private Class<?> taskClass;

    private List<Integer> parentIdList = new ArrayList<>();

    private List<Config> parentConfigList;

    public Class<?> getTaskClass() {
        if (taskClass == null) {
            try {
                taskClass = getClass().getClassLoader().loadClass(taskName);
            } catch (ClassNotFoundException e) {
                log.error("taskClass load fail:{}", taskName, e);
                throw new RuntimeException(e);
            }
        }
        return taskClass;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Config config = (Config) o;

        if (!Objects.equals(taskName, config.taskName)) {
            return false;
        }
        return true;
    }

//    @Override
//    public int hashCode() {
//        int result = id != null ? id.hashCode() : 0;
//        result = 31 * result + (taskName != null ? taskName.hashCode() : 0);
//        result = 31 * result + (taskClass != null ? taskClass.hashCode() : 0);
//        result = 31 * result + (parentIdList != null ? parentIdList.hashCode() : 0);
//        result = 31 * result + (parentConfigList != null ? parentConfigList.hashCode() : 0);
//        return result;
//    }
}
